<?php
if(isset($_GET['id']) && isset($_GET['page']))
{	session_start();
	$id = $_GET['id'];
	$page = $_GET['page'];
	include_once("../DataProvider.php");
	if($id == 0)
	{
		$sql = "select * from tbl_games";
	}
	else
	{
		$sql = "select * from tbl_games where Categories = $id";
	}$result = DataProvider::ExecuteQuery($sql);
	$tongsorecord = mysql_num_rows($result);
	$y = 9;
	$start = ($page-1)*$y;
	$tongsotrang = ceil($tongsorecord/$y);
	if($tongsorecord == 0){
		echo "Không có tin nào";	
	}else{
	?>
    
   <table width="760">
   <tr>
   <td>
    <?php
		$stt = 0;
		if($id ==0)
		{
			$sql1 = "select * from tbl_games order by gameName limit $start,$y";
		}
		else
		{
			$sql1 = "select * from tbl_games where CategoriesID = $id order by gameName limit $start,$y";
		}
		
		$result1 = DataProvider::ExecuteQuery($sql1);
		while($data1 = mysql_fetch_array($result1)){
						?>
	<div class="pic">
     <div class="mask" onclick="javascript:add('<?php echo $data1["gameID"]; ?>')"id="chk<?php echo $data1["gameID"];?>" style="position: absolute; cursor: pointer;display:
	 <?php if(isset($_SESSION["listGame"]))
	 { 
	 	if(in_array($data1["gameID"],$_SESSION["listGame"]))
		{
			echo "block;";
			
			}
			else
			{
				echo "none;";
				}
		
		
	 }else echo "none;";
	 ?>"></div>
     <div style="position: absolute; height:250px;"><div id="a<?php echo $data1["gameID"];?>" style="display:none; position:absolute; margin-left:30px; ">
    <img src="img/add.png"/></div>
     <div onmouseout="javascript:mouseout(this)" onmouseover="javascript:mouseover(this)" id="div<?php echo $data1["gameID"];?>" style="background: url(<?php echo $data1["Artwork"];?>)no-repeat; float:left; margin-left:15px; margin-top:5px; background-size:100px;">
	<img id="img<?php echo $data1["gameID"]; ?>" class="<?php if(isset($_SESSION['listGame']))
	 { 
	 	if(in_array($data1['gameID'],$_SESSION['listGame']))
		{
			echo 'Selected';
			
			}
			else
			{
				echo 'unSelect';
				}
		
		
	 }else echo 'unSelect';
	 ?>" alt="<?php echo $data1['GameName']; ?>" src="img/mask175_2.png" height="100px" width="100px" style=" cursor: pointer;" onclick="javascript:add('<?php echo $data1["gameID"]; ?>')" />
    </div>
    

<div class="textGame" title="<?php echo $data1['gameName'];?>">
<?php 
if(strlen($data1["gameName"])>15)
{echo (substr( $data1["gameName"],0,15)."...");}
else{ echo $data1["gameName"];} ?>

<br /> <span style="color:#C33; font-size:12px"><?php echo number_format($data1["Price"], 0, '.', ',');?> </span>VNĐ&nbsp;&nbsp;<span style="color:#666;"><?php if($data1["Size"]>1000)	
	 		echo number_format($data1["Size"]/1000,2,".",","). " GB"; 
		else
			echo number_format($data1["Size"],2,".",",") . " MB";?></span></div>
<p><a style="cursor:pointer;" id="<?php echo $data1["gameID"] ?>" onclick="javascript:loadScreenShoot(<?php echo $data1["gameID"];  ?>)"><img src="img/12.png" alt="img" /></a></p></div></div>

	<?php	}
	}?>


       </td></tr><tr align="center"><td> <div id="pt" align="center"><span style=" margin-right:1px;color:#000; background-color:#fff;border:solid;  border-color:#000; border-width:2px;">&nbsp;Trang <?php echo $page."/".$tongsotrang; ?>&nbsp;</span>
        <?php
        if($page == 1)
				{echo"<span class='active' style='color:#000; background-color:#fff;border:solid; border-color:#000; border-width:2px;'><<</span>";}
				else
				{
				echo"<span class='paging'><a style='text-decoration:none;' href='#1' onclick='javascript:loadGame(1,1);'><< </a> </span>";}
			for($i=1;$i<=$tongsotrang;$i++){
				
				if($i == $page){
				 echo "<span class='active' style=' margin-right:1px; ; background-color:#fff;border:solid; border-color:#000; border-width:2px;'>$i</span>";	
				}else{
					echo "<span class='paging'><a style='text-decoration:none;' href='#$i' onclick='javascript:loadGame($i+1,$i);'> $i</a>  </span>";	
				}
			}
			if($page == $tongsotrang)
				{echo"<span class='active' style='  background-color:#fff;border:solid; border-color:#000; border-width:2px;'>>></span>";}
				else
				{
				echo"<span class='paging' ><a style='text-decoration:none;' href='#$i' onclick='javascript:loadGame(1,$tongsotrang);'> >> </a></span>";
				}
}?>
</div></td></tr></table>